<?php
    ini_set('date.timezone','Asia/Shanghai');
    header("content-type:text/html;charset=utf-8");

    $mysql_conf = array(
        'host'    => '127.0.0.1', 
        'db'      => 'yjhx', 
        'db_user' => 'root', 
        'db_pwd'  => 'root', 
    );

    $mysqli = @new mysqli($mysql_conf['host'],$mysql_conf['db_user'],$mysql_conf['db_pwd']);
        if ($mysqli->connect_errno) {
            die("could not connect to the database:\n" . $mysqli->connect_error);//诊断连接错误
        }
        $mysqli->query("set names 'utf8';");//编码转化
        $select_db = $mysqli->select_db($mysql_conf['db']);
        if (!$select_db) {
            die("could not connect to the db:\n" .  $mysqli->error);
        }

    $sql ="SELECT * FROM user";

    $query = $mysqli->query($sql);

    //将查询的结果集封装到一个数组里
    
    $result=$query->fetch_all();
    // foreach ($result as $key => $value) {
    //     $timestamp = strtotime($value[4]);
    //     $difference = time()-$timestamp;
    //     if($difference <= 180){
    //         $css[$key][4] = '刚刚';
    //     }elseif($difference <= 3600){
    //         $css[$key][4] = ceil($difference/60).'分钟前';
    //     }elseif($difference <= 86400){
    //         $css[$key][4] = ceil($difference/3600).'小时前';
    //     }elseif($difference <= 2592000){
    //         $css[$key][4] = ceil($difference/86400).'天前';
    //     }elseif($difference <= 31536000){
    //         $css[$key][4] = ceil($difference/2592000).'个月前';
    //     }else{
    //         $css[$key][4] = ceil($difference/31536000).'年前';
    //         // $css[$key]['create_time'] = $date_time;
    //     }
    // }
    echo json_encode($result);

    // foreach ($css as $key => $value) {
    //     $timestamp = strtotime($value['create_time']);
    //     $difference = time()-$timestamp;
    //     if($difference <= 180){
    //         $css[$key]['create_time'] = '刚刚';
    //     }elseif($difference <= 3600){
    //         $css[$key]['create_time'] = ceil($difference/60).'分钟前';
    //     }elseif($difference <= 86400){
    //         $css[$key]['create_time'] = ceil($difference/3600).'小时前';
    //     }elseif($difference <= 2592000){
    //         $css[$key]['create_time'] = ceil($difference/86400).'天前';
    //     }elseif($difference <= 31536000){
    //         $css[$key]['create_time'] = ceil($difference/2592000).'个月前';
    //     }else{
    //         $css[$key]['create_time'] = ceil($difference/31536000).'年前';
    //         // $css[$key]['create_time'] = $date_time;
    //     }

    // }
    //以json的格式发送ajax的success中由data接收
    
    while ($row = $query->fetch_array()) {
        echo 'ID：'.$row['Id'].'<br>姓名：'.$row['name'].'<br>电话号码：'.$row['telphone'].'<br>提交时间：'.$row['create_time'].'<br>客户端ip：'.$row['ip'].'<br>------------------------------------<br>';
    }


    //释放资源
    $query->close();
    $mysqli->close();



?>